﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

namespace GPSTrackingAdminWebsiteManager.Espanol.Pages
{
    public partial class ImeiType : Telerik.Web.UI.RadAjaxPage
    {

        private GPSTrackingServerDB.Entities.ImeiType Invoke_Vehicule(Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridEditableItem item = e.Item as GridEditableItem;
            Hashtable entity = new Hashtable();
            item.ExtractValues(entity);

            GPSTrackingServerDB.Entities.ImeiType imeiTypeEntity = new GPSTrackingServerDB.Entities.ImeiType();
            imeiTypeEntity.Description = entity[GPSTrackingServerDB.Entities.ImeiTypeColumn.Description.ToString()].ToString();
            imeiTypeEntity.Image = entity[GPSTrackingServerDB.Entities.ImeiTypeColumn.Image.ToString()].ToString();

            return imeiTypeEntity;
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void VehiculeTypesGrid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {

            VehiculeTypesGrid.DataSource = GPSTrackingServerDB.Data.DataRepository.ImeiTypeProvider.GetAll();
        }

        protected void VehiculeTypesGrid_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GPSTrackingServerDB.Entities.ImeiType vehicleTypeEntity = Invoke_Vehicule(e);

            GPSTrackingServerDB.Data.DataRepository.ImeiTypeProvider.Insert(vehicleTypeEntity);
        }

        protected void VehiculeTypesGrid_UpdateCommand(object sender, GridCommandEventArgs e)
        {
            GPSTrackingServerDB.Entities.ImeiType vehicleTypeEntity = Invoke_Vehicule(e);

            GridEditableItem editedItem = e.Item as GridEditableItem;

            vehicleTypeEntity.ImeiTypeId = Convert.ToInt32(editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["ImeiTypeID"]);

            GPSTrackingServerDB.Data.DataRepository.ImeiTypeProvider.Update(vehicleTypeEntity);
        }

        protected void VehiculeTypesGrid_DeleteCommand(object sender, GridCommandEventArgs e)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            GPSTrackingServerDB.Data.DataRepository.ImeiTypeProvider.Delete(Convert.ToInt32(editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["ImeiTypeID"]));
        }

       
    }
}